# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>

pkgname=vals
pkgver=0.19.0
pkgrel=1
pkgdesc="Helm-like configuration values loader with support for various sources"
arch=('loong64' 'x86_64')
url="https://github.com/variantdev/vals"
license=('Apache')
makedepends=('go')
depends=('glibc')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/variantdev/vals/archive/v${pkgver}.tar.gz")
sha512sums=('031f6d07a4976c0b7a1c8c225c64c7855cae92d437639322f70f6694a655ca6309e5bb7bdbe0f969a75dab3676d0355d96e9a424e233af68b3d67bf7eafb7606')
options=(!lto)

prepare() {
  export GOPATH="${srcdir}"
  mkdir -p src/github.com/variantdev "${GOPATH}/bin"
  mv "${pkgname}-${pkgver}" "src/github.com/variantdev/${pkgname}"
  export PACKAGE_ROOT="${GOPATH}/src/github.com/variantdev/${pkgname}"
}

build() {
  cd "${PACKAGE_ROOT}"
  export CGO_ENABLED=1
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  export GOLDFLAGS="-linkmode=external"
  go build -v ./cmd/vals
  chmod +x ./vals
}

# Failing tests due to Google Cloud dependency
#check() {
#  cd "${PACKAGE_ROOT}"
#  go test -v ./...
#}

package() {
  cd "${PACKAGE_ROOT}"
  install -Dsm755 ./vals "${pkgdir}/usr/bin/vals"
}
